package single.demo01;

/**
 * 饿汉式（静态变量）
 *
 * 可能造成内存浪费
 *
 * instance在类装载的时候就实例化了
 *
 *
 */
public class Demo01 {

    public static void main(String[] args) {

        Single instance1 = Single.getInstance();
        Single instance2 = Single.getInstance();
        System.out.println(instance1 == instance2);
        System.out.println("hashCode1:"+instance1.hashCode());
        System.out.println("hashCode2:"+instance2.hashCode());

    }

}


class Single{

    private Single(){};

    private  final static Single instance = new Single();

    public static Single getInstance(){
        return instance;
    }
}